package com.qf.flash.mvp.presenter;

import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.http.HttpManager;
import com.qf.flash.model.GameGroupBean;
import com.qf.flash.mvp.contract.OrderHallContract;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseResponse;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

import java.util.List;

/**
 * 描述: 商家订单大厅
 * 2020/3/24 14:20
 */
public class OrderHallPresenter extends BasePresenter<OrderHallContract.View> implements OrderHallContract.Presenter {
    @Override
    public void getGameList(int page) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .OPEN_ORDER_LIST(uid, page)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<List<GameGroupBean>>>(
                        mRootView, false) {
                    @Override
                    public void onSuccess(BaseResponse<List<GameGroupBean>> game) {
                        mRootView.setGameList(game.getData(), game.getTotalPage());
                    }
                })
        );
    }

    @Override
    public void receiveOrRejectOrder(String orderId, int optionType) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .RECEIVE_REJECT(uid, orderId, optionType)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<Object>(mRootView) {
                    @Override
                    public void onSuccess(Object o) {
                        mRootView.receiveOrRejectOrderSuccess(optionType);
                    }
                })
        );
    }

}
